package com.jeecg.demo.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeecg.demo.entity.AppUserBehaviorNotesEntity;
import com.jeecg.demo.service.AppUserBehaviorNotesServiceI;
import com.jeecg.demo.util.TimerUtil;

/**
 * 行为记录
 * 
 * @author Administrator
 * 
 */
@Api(value = "AppUserBehaviorNotes", description = "行为记录表", tags = "AppUserBehaviorNotes")
@Controller
@RequestMapping("/visitLog")
public class VisitLog {
	@Autowired
	private AppUserBehaviorNotesServiceI appUserBehaviorNotesServiceI;
	@Autowired
	private SystemService systemService;

	@RequestMapping(value = "/behaviorNotes", method = RequestMethod.POST)
	@ResponseBody
	@Transactional(isolation = Isolation.READ_COMMITTED, timeout = 5)
	@ApiOperation(value = "行为记录")
	public ResponseMessage<?> saveVisitLog(
			@RequestParam(required = false) String userid, // 用户编号
			@RequestParam(required = false) int systemid, // 系统编号：1 手机 2 管理后台
			@RequestParam(required = false) int behavior_type, // 行为类型：1、新闻阅读2、新闻分享3、广告轮播
			@RequestParam(required = false) String behavior_desc// 访问内容 ：信息id

	) {
		if (StringUtil.isEmpty(userid)) {
			return Result.error("用户编号不能为空");
		}
		if (StringUtil.isEmpty(systemid + "")) {
			return null;
		}
		if (StringUtil.isEmpty(behavior_type + "")) {
			return null;
		}
		if (StringUtil.isEmpty(behavior_desc)) {
			return null;
		}
		AppUserBehaviorNotesEntity appUserBehaviorNotesEntity = new AppUserBehaviorNotesEntity();
		try {
			appUserBehaviorNotesEntity.setUserid(userid);
			appUserBehaviorNotesEntity.setSystemid(systemid);
			appUserBehaviorNotesEntity.setBehaviorType(behavior_type);
			appUserBehaviorNotesEntity.setBehaviorDesc(behavior_desc);
			appUserBehaviorNotesEntity.setVisitDate(TimerUtil
					.getCurrentTimeStamp());
			appUserBehaviorNotesServiceI.save(appUserBehaviorNotesEntity);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("失败");
		}
		return Result.success(appUserBehaviorNotesEntity);
	}
}
